$(document).ready(function () {

    const id = $("#id").val();

    $("#menu input").on("click", function () {
        window.location.href = "showlist";
    });

    $("#title input").on("click", function () {
        window.location.href = "../pipe/insert?id=" + id;
    });

    $("#table2 tbody tr").each(function () {
        const id = $(this).attr("id");
        /** 编辑管道 */
        $(this).find("input:eq(0)").on("click", function () {
            window.location.href = "../pipe/editinfo?id=" + id;
        });
        /** 删除管道 */
        $(this).find("input:eq(1)").on("click", function () {
            if (!confirm("Are you sure you want to delete this data?"))
                return false;
            $(this).css("background-color", "#CCC");
            $(this).attr("disabled", true);
            Ajax("../pipe/delete", {id: id})
            setTimeout("location.reload()", 2000);
        });
    });

    function Ajax(url, data) {
        let result = null;
        $.ajax({
            url: url,
            data: data,
            type: "post",
            async: false,
            datatype: "json",
            success: function (data) {
                result = data;
            }
        });
        return result;
    }
});